﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.ComponentModel;

namespace WPF.Controls.QuerySelector
{
    public static class QuerySelector
    {
        public static object Attr(this FrameworkElement element, string attr)
        {
            PropertyInfo info = element.GetType().GetProperty(attr);
            return info.GetValue(element, null);
           
        }

        public static FrameworkElement Attr(this FrameworkElement element, string key,object value)
        {
            PropertyInfo info = element.GetType().GetProperty(key);
            info.SetValue(element,value,null);
            
            return element;
        }

        public static FrameworkElement Attr(this FrameworkElement element, Dictionary<string,object> properties)
        {
            foreach (var item in properties)
            {
                element.Attr(item.Key, item.Value);
            }
            return element;
        }

        public static FrameworkElement removeAttr(this FrameworkElement element, string name)
        {
            DependencyProperty dp=DependencyPropertyDescriptor.FromName(name, element.GetType(), element.GetType()).DependencyProperty;
            element.ClearValue(dp);
            return element;
        }
    }
}
